//
//  DisplayTestController.m
//  JsUtilityDemo
//
//  Created by Gikki Ares on 2021/9/24.
//

#import "StringValidatorViewController.h"
#import <JsUtilitySdk/JsUtilitySdk.h>

@interface StringValidatorViewController ()<
	JsMenuViewDelegate
>

{
	JsMenuView * mMenuView;
	UITextView * mtv;
}

@end

@implementation StringValidatorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	[self setupUi];
}

- (void)setupUi {
	self.view.backgroundColor = [UIColor whiteColor];
	{
		mtv = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, JsGeometryManager.screenWidth, 300)];
		[self.view addSubview:mtv];
		mtv.text = @"https://www.baidu.com";
	}
	{
	if(!mMenuView) {
		CGRect frame = [JsGeometryManager frameHAlignCenterVAlignBottomWithContainerSize:self.view.frame.size size:CGSizeMake(JsGeometryManager.screenSize.width, 300)];
		JsMenuView * mMenuView = [[JsMenuView alloc]initWithFrame:frame];
		mMenuView.delegate = self;
		[self.view addSubview:mMenuView];
	}
	}
}

#pragma mark JsMenuViewDelegate
- (NSArray<JsMenuItemVm *> *)jsMenuViewSetDatasource:(JsMenuView *)view {
	return @[
		[[JsMenuItemVm alloc]initWithTitle:@"UrlTest"],
		[[JsMenuItemVm alloc]initWithTitle:@"RtmpTest"],
		[[JsMenuItemVm alloc]initWithTitle:@"HlsTest"],
	];
}

- (void)jsMenuView:(JsMenuView *)view clickMenuAtIndex:(int)index vm:(JsMenuItemVm *)vm {
	NSString * str = mtv.text;
	switch (index) {
		case 0:{
			if([JsStringValidator isValidUrlString:str]) {
				[self.view displayMessage:@"This is a valid url string!"];
			}
			else {
				[self.view displayMessage:@"This is a invalid url string!"];
			}
			break;
		}
		case 1:{
			if([JsStringValidator isValidRtmpString:str]) {
				[self.view displayMessage:@"This is a valid rtmp string!"];
			}
			else {
				[self.view displayMessage:@"This is a invalid rtmp string!"];
			}
			break;
		}
		case 2:{
			if([JsStringValidator isValidHlsString:str]) {
				[self.view displayMessage:@"This is a valid hls string!"];
			}
			else {
				[self.view displayMessage:@"This is a invalid hls string!"];
			}
			break;
		}

		default:
			break;
	}
}





@end
